<?php
class Kota_model extends MY_Model {
	
    function Kota_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "kota";
    }
    
    function select_last_entry($search_key=false, $where=false, $limit=10, $offset=0, $orderby=""){
    	$sql = $sqlo = $sqlw = "";
    	
    	$sqlw = " WHERE a.propinsi_id=b.propinsi_id ";
    	if ($search_key){
    		$sqlw .= ($sqlw? " AND " : ""). 
    				"(a.kota_id LIKE '%$search_key%' OR 
    				 a.kota_nama LIKE '%$search_key%' OR
    				 a.kota_kode_pos LIKE '%$search_key%' OR
    				 a.kota_kode_area_telepon LIKE '%$search_key%' OR
    				 b.propinsi_nama LIKE '%$search_key%')";
    	}
    	if ($where){
    		$sqlw .= ($sqlw? " AND " : "").$where;
    	}
    	
    	if ($orderby){
    		$sqlo = "ORDER BY $orderby";
    	}
    	return $query = $this->db->query(
    		"SELECT a.kota_id, a.kota_nama, a.kota_kode_pos, a.kota_kode_area_telepon, b.propinsi_nama 
    		FROM ".$this->table_name." as a, propinsi as b".
    		"$sqlw $sqlo LIMIT $offset,$limit");
    }
        
    function select_by_id($id){
    	return $query = $this->db->get_where($this->table_name, array('kota_id' => $id));
    }
}